package www.golf.web;

import java.util.HashMap;
import java.util.Map;

import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Iframe;
import org.zkoss.zul.Include;
import org.zkoss.zul.Menuitem;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Window;

import www.golf.ibatis.IBatisFactory;
import www.golf.web.session.WebSession;
import www.golf.web.util.UtilZKObject;

public class MainControl extends WebSession {
	UtilZKObject zkObject =new UtilZKObject(this);
	WebSession ws= new WebSession();
	public void initialize() {
		getPage().addEventListener("onBookmarkChange",
		    new org.zkoss.zk.ui.event.EventListener() {
			@Override
			public void onEvent(Event event) throws Exception {
				String marker=getDesktop().getBookmark();
				if(getFellowIfAny(marker)!=null&&getFellowIfAny(marker) instanceof Menuitem){
					menuClick(getDesktop().getBookmark());
				}else{
					((Include)getFellow("m_content")).setSrc("../main/content.zul");
					getDesktop().setBookmark("");
				}
			}
		});
		if(conditionLoginSession()){
			setPowerMenu();
		}
	}
	public void menuClick(String st) {
		String s[]=st.split("_");
		String type=s[0];
		String page=s[1];
		((Include)getFellow("m_content")).setSrc("../"+type+"/"+page+"/"+page+".zul");
		setPagefileSession("../"+type+"/"+page+"/");
		getDesktop().setBookmark(st);
	}
	public void setPowerMenu(){
		if(getUserPower()>5){
			getFellow("system").setVisible(false);
		}
	}
	public void logout() {
		try {
			if(Messagebox.show("已登出")!=-1){
				Executions.getCurrent().getSession().invalidate();
				Executions.getCurrent().sendRedirect("../index.zul");
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}